<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
<script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/picture/pika.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/picture/pika.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="code-LqqDM3vffE">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">


  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/2efd5eff.js","daovoice")
  daovoice('init', {
    app_id: "2efd5eff"
  });
  daovoice('update');
  </script>


<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"notspr.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":true,"color":"#ff7600","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":false,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="前言 蓝鲸监控通过 job 部署 prometheus 社区的 Exporter，对目标组件进行性能数据采集。接着 bkmetricbeat 从 Exporter 上周期拉取性能数据并通过数据通道上报。 自定义组件采集导入流程蓝鲸监控当前支持使用 go 编写 Exporter  在社区找到适合自己的 Exporter 或者编写新的 Exporter  将源码编译成二进制文件  将编译的 Expo">
<meta property="og:type" content="article">
<meta property="og:title" content="GO语言之Prometheus Exporter开发">
<meta property="og:url" content="https://notspr.com/2020/11/25/go-prometheus-export/index.html">
<meta property="og:site_name" content="Sapphire">
<meta property="og:description" content="前言 蓝鲸监控通过 job 部署 prometheus 社区的 Exporter，对目标组件进行性能数据采集。接着 bkmetricbeat 从 Exporter 上周期拉取性能数据并通过数据通道上报。 自定义组件采集导入流程蓝鲸监控当前支持使用 go 编写 Exporter  在社区找到适合自己的 Exporter 或者编写新的 Exporter  将源码编译成二进制文件  将编译的 Expo">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-11-24T16:52:59.000Z">
<meta property="article:modified_time" content="2020-12-01T17:48:45.202Z">
<meta property="article:author" content="Ryan Shu">
<meta property="article:tag" content="Golang">
<meta property="article:tag" content="Prometheus">
<meta property="article:tag" content="Exporter">
<meta property="article:tag" content="监控">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://notspr.com/2020/11/25/go-prometheus-export/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>GO语言之Prometheus Exporter开发 | Sapphire</title>
  


  <script data-pjax>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?2907d577c8c6c2f7fe3843736d24280d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <!--pjax：防止跳转页面音乐暂停-->
  <script src="https://cdn.jsdelivr.net/npm/pjax@0.2.8/pjax.js"></script>
<link rel="alternate" href="/atom.xml" title="Sapphire" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Sapphire</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">興趣使然的博客</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/aboutme/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">82</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">34</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">40</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/sususama5555" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://notspr.com/2020/11/25/go-prometheus-export/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/picture/avatar.jpg">
      <meta itemprop="name" content="Ryan Shu">
      <meta itemprop="description" content="全栈 | 硬件 | 篮球 | 游戏">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Sapphire">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          GO语言之Prometheus Exporter开发
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-11-25 00:52:59" itemprop="dateCreated datePublished" datetime="2020-11-25T00:52:59+08:00">2020-11-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Golang/" itemprop="url" rel="index"><span itemprop="name">Golang</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Golang/Prometheus/" itemprop="url" rel="index"><span itemprop="name">Prometheus</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <blockquote>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2></blockquote>
<p>蓝鲸监控通过 job 部署 prometheus 社区的 Exporter，对目标组件进行性能数据采集。接着 bkmetricbeat 从 Exporter 上周期拉取性能数据并通过数据通道上报。</p>
<h3 id="自定义组件采集导入流程"><a href="#自定义组件采集导入流程" class="headerlink" title="自定义组件采集导入流程"></a>自定义组件采集导入流程</h3><p>蓝鲸监控当前支持使用 go 编写 Exporter</p>
<ul>
<li><p>在社区找到适合自己的 Exporter 或者编写新的 Exporter</p>
</li>
<li><p>将源码编译成二进制文件</p>
</li>
<li><p>将编译的 Exporter 打成 zip 包</p>
</li>
<li><p>上传配置文件</p>
</li>
</ul>
<a id="more"></a>

<h2 id="Exporter-开发"><a href="#Exporter-开发" class="headerlink" title="Exporter 开发"></a>Exporter 开发</h2><h3 id="Exporter-简介"><a href="#Exporter-简介" class="headerlink" title="Exporter 简介"></a>Exporter 简介</h3><ul>
<li>Exporter 本质上就是将收集的数据，转化为对应的⽂本格式，并提供 http 接口，供蓝鲸监控采集器 定期采集数据。</li>
</ul>
<h3 id="Exporter-基础"><a href="#Exporter-基础" class="headerlink" title="Exporter 基础"></a>Exporter 基础</h3><ul>
<li><p>指标介绍 Prometheus 中主要使⽤的四类指标类型，如下所示：</p>
<ul>
<li>Counter (累加指标)</li>
<li>Gauge (测量指标)</li>
<li>Summary (概略图)</li>
<li>Histogram (直方图)</li>
</ul>
<p>最常使用的是 Gauge，Gauge 代表了采集的一个单个数据，这个数据可以增加也可以减少，比如 CPU 使用情况，内存使用量，硬盘当前的空间容量等。 Counter 一个累加指标数据，这个值随着时间只会逐渐的增加，比如程序完成的总任务数量，运行错误发生的总次数等，代表了持续增加的数据包或者传输字节累加值。</p>
<blockquote>
<p>【注】：所有指标的值仅支持 float64 类型。</p>
</blockquote>
</li>
<li><p>文本格式以下面输出为例：</p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># metric:</span></span><br><span class="line">sample_metric1 12.47</span><br><span class="line">sample_metric2 &#123;partition=<span class="string">"c:"</span>&#125; 0.44</span><br></pre></td></tr></table></figure>

<p>其中：</p>
<p>#: 表示注释 sample_metric1 和 sample_metric2 表示指标名称</p>
<p>partition: 表示指标的作⽤维度，例如磁盘分区使⽤率，维度就是磁盘分区，即每个磁盘分区都有⼀个磁盘分区使⽤率的值</p>
<p>c: 表示维度的值，例如磁盘分区的 C 盘 / D 盘等 12.47 和 0.44 表示对应指标的值</p>
<h3 id="Exporter-开发-1"><a href="#Exporter-开发-1" class="headerlink" title="Exporter 开发"></a>Exporter 开发</h3><ul>
<li><p>环境搭建：</p>
<ul>
<li>Golang 安装</li>
<li>apt-get install git</li>
<li>wget <a href="https://dl.google.com/go/go1.10.7.linux-amd64.tar.gz" target="_blank" rel="noopener">https://dl.google.com/go/go1.10.7.linux-amd64.tar.gz</a></li>
<li>tar -C /usr/local -xzf go1.10.7.linux-amd64.tar.gz</li>
<li>export PATH=$PATH:/usr/local/go/bin</li>
<li>export GOPATH=<code>你的代码目录</code></li>
</ul>
<blockquote>
<p>不同系统安装介绍：<a href="https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.1.md" target="_blank" rel="noopener">https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.1.md</a></p>
</blockquote>
</li>
<li><p>Prometheus Exporter 开发依赖库</p>
<p>⾸先引⼊ Prometheus 的依赖库</p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go get -v github.com/prometheus/client_golang/prometheus</span><br></pre></td></tr></table></figure>

<ul>
<li>开发示例</li>
</ul>
<ol>
<li>导⼊依赖模块: 本例计划采集主机的内存和磁盘信息，因此引⼊以下依赖库</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">go get -v github.com/shirou/gopsutil</span><br><span class="line">go get -v github.com/go-ole/go-ole</span><br><span class="line">go get -v github.com/StackExchange/wmi</span><br><span class="line">go get -v github.com/golang/protobuf/proto</span><br><span class="line">go get -v golang.org/x/sys/unix</span><br></pre></td></tr></table></figure>

<ol>
<li>新建⼀个 Exporter 项⽬： ⼀个 Exporter 只需要⼀个⽂件即可；在 GOPATH 下 src ⽬录下新建⼀个 test_exporter ⽬录和⼀个 test_exporter.go ⽂件: test_exporter.go ⽂件第⼀⾏必须写上 package main 可执⾏的命令必须始终使⽤ package main。</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">"flag"</span></span><br><span class="line">	<span class="string">"log"</span></span><br><span class="line">	<span class="string">"net/http"</span></span><br><span class="line"></span><br><span class="line">	<span class="string">"github.com/prometheus/client_golang/prometheus"</span></span><br><span class="line">	<span class="string">"github.com/prometheus/client_golang/prometheus/promhttp"</span></span><br><span class="line">	<span class="string">"github.com/shirou/gopsutil/disk"</span></span><br><span class="line">	<span class="string">"github.com/shirou/gopsutil/mem"</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<ol>
<li>定义 Exporter 的版本（Version）、监听地址（listenAddress）、采集 url（metricPath）以及⾸⻚（landingPage）</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> (</span><br><span class="line">	Version       = <span class="string">"1.0.0.dev"</span></span><br><span class="line">	listenAddress = flag.String(<span class="string">"web.listen-address"</span>, <span class="string">":9601"</span>, <span class="string">"Address to listen on for web interface and telemetry."</span>)</span><br><span class="line">	metricPath    = flag.String(<span class="string">"web.telemetry-path"</span>, <span class="string">"/metrics"</span>, <span class="string">"Path under which to expose metrics."</span>)</span><br><span class="line">	landingPage   = []<span class="keyword">byte</span>(<span class="string">"&lt;html&gt;&lt;head&gt;&lt;title&gt;Example Exporter"</span> + Version + <span class="string">"&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Example Exporter"</span> + Version + <span class="string">"&lt;/h1&gt;&lt;p&gt;&lt;ahref='"</span> + *metricPath + <span class="string">"'&gt;Metrics&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;"</span>)</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<ol>
<li>定义 Exporter 结构体</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> Exporter <span class="keyword">struct</span> &#123;</span><br><span class="line">	error        prometheus.Gauge</span><br><span class="line">	scrapeErrors *prometheus.CounterVec</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>定义结构体实例化的函数 NewExporter</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">NewExporter</span><span class="params">()</span> *<span class="title">Exporter</span></span> &#123;</span><br><span class="line">	<span class="keyword">return</span> &amp;Exporter&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>Describe 函数，传递指标描述符到 channel，这个函数不⽤动，直接使⽤即可，⽤来⽣成采集指标的描述信息。</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="params">(e *Exporter)</span> <span class="title">Describe</span><span class="params">(ch <span class="keyword">chan</span>&lt;- *prometheus.Desc)</span></span> &#123;</span><br><span class="line">	metricCh := <span class="built_in">make</span>(<span class="keyword">chan</span> prometheus.Metric)</span><br><span class="line">	doneCh := <span class="built_in">make</span>(<span class="keyword">chan</span> <span class="keyword">struct</span>&#123;&#125;)</span><br><span class="line">	<span class="keyword">go</span> <span class="function"><span class="keyword">func</span><span class="params">()</span></span> &#123;</span><br><span class="line">		<span class="keyword">for</span> m := <span class="keyword">range</span> metricCh &#123;</span><br><span class="line">			ch &lt;- m.Desc()</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">close</span>(doneCh)</span><br><span class="line">	&#125;()</span><br><span class="line">	e.Collect(metricCh)</span><br><span class="line">	<span class="built_in">close</span>(metricCh)</span><br><span class="line">	&lt;-doneCh</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>Collect 函数将执⾏抓取函数并返回数据，返回的数据传递到 channel 中，并且传递的同时绑定原先的指标描述符，以及指标的类型（Guage）；需要将所有的指标获取函数在这⾥写⼊。</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//collect 函数，采集数据的⼊⼝</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="params">(e *Exporter)</span> <span class="title">Collect</span><span class="params">(ch <span class="keyword">chan</span>&lt;- prometheus.Metric)</span></span> &#123;</span><br><span class="line">	<span class="keyword">var</span> err error</span><br><span class="line">	<span class="comment">// 每个指标值的采集逻辑，在对应的采集函数中</span></span><br><span class="line">	<span class="keyword">if</span> err = ScrapeMem(ch); err != <span class="literal">nil</span> &#123;</span><br><span class="line">		e.scrapeErrors.WithLabelValues(<span class="string">"mem"</span>).Inc()</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span> err = ScrapeDisk(ch); err != <span class="literal">nil</span> &#123;</span><br><span class="line">		e.scrapeErrors.WithLabelValues(<span class="string">"disk"</span>).Inc()</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>指标仅有单条数据，不带维度信息示例如下：</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">ScrapeMem</span><span class="params">(ch <span class="keyword">chan</span>&lt;- prometheus.Metric)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">	<span class="comment">// 指标获取逻辑，此处不做具体操作，仅仅赋值进⾏示例</span></span><br><span class="line">	mem_info, _ := mem.VirtualMemory()</span><br><span class="line">	<span class="comment">// ⽣成采集的指标名</span></span><br><span class="line">	metric_name := prometheus.BuildFQName(<span class="string">"sys"</span>, <span class="string">""</span>, <span class="string">"mem_usage"</span>)</span><br><span class="line">	<span class="comment">// ⽣成 NewDesc 类型的数据格式，该指标⽆维度，[] string &#123;&#125; 为空</span></span><br><span class="line">	new_desc := prometheus.NewDesc(metric_name, <span class="string">"Gauge metric with mem_usage"</span>, []<span class="keyword">string</span>&#123;&#125;, <span class="literal">nil</span>)</span><br><span class="line">	<span class="comment">// ⽣成具体的采集信息并写⼊ ch 通道</span></span><br><span class="line">	metric_mes := prometheus.MustNewConstMetric(new_desc,</span><br><span class="line">		prometheus.GaugeValue, mem_info.UsedPercent)</span><br><span class="line">	ch &lt;- metric_mes</span><br><span class="line">	<span class="keyword">return</span> <span class="literal">nil</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>指标有多条数据，带维度信息示例如下：</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">ScrapeDisk</span><span class="params">(ch <span class="keyword">chan</span>&lt;- prometheus.Metric)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">	fs, _ := disk.Partitions(<span class="literal">false</span>)</span><br><span class="line">	<span class="keyword">for</span> _, val := <span class="keyword">range</span> fs &#123;</span><br><span class="line">		d, _ := disk.Usage(val.Mountpoint)</span><br><span class="line">		metric_name := prometheus.BuildFQName(<span class="string">"sys"</span>, <span class="string">""</span>, <span class="string">"disk_size"</span>)</span><br><span class="line">		new_desc := prometheus.NewDesc(metric_name, <span class="string">"Gauge metric with disk_usage"</span>, []<span class="keyword">string</span>&#123;<span class="string">"mountpoint"</span>&#125;, <span class="literal">nil</span>)</span><br><span class="line">		metric_mes := prometheus.MustNewConstMetric(new_desc,</span><br><span class="line">			prometheus.GaugeValue, <span class="keyword">float64</span>(d.UsedPercent), val.Mountpoint)</span><br><span class="line">		ch &lt;- metric_mes</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="literal">nil</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>主函数</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	<span class="comment">// 解析定义的监听端⼝等信息</span></span><br><span class="line">	flag.Parse()</span><br><span class="line">	<span class="comment">// ⽣成⼀个 Exporter 类型的对象，该 exporter 需具有 collect 和 Describe ⽅法</span></span><br><span class="line">	exporter := NewExporter()</span><br><span class="line">	<span class="comment">// 将 exporter 注册⼊ prometheus，prometheus 将定期从 exporter 拉取数据</span></span><br><span class="line">	prometheus.MustRegister(exporter)</span><br><span class="line">	<span class="comment">// 接收 http 请求时，触发 collect 函数，采集数据</span></span><br><span class="line">	http.Handle(*metricPath, promhttp.Handler())</span><br><span class="line">	http.HandleFunc(<span class="string">"/"</span>, <span class="function"><span class="keyword">func</span><span class="params">(w http.ResponseWriter, r *http.Request)</span></span> &#123;</span><br><span class="line">		w.Write(landingPage)</span><br><span class="line">	&#125;)</span><br><span class="line">	log.Fatal(http.ListenAndServe(*listenAddress, <span class="literal">nil</span>))</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>编译 Exporter</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">go build test_exporter.go</span><br><span class="line">./test_exporter</span><br></pre></td></tr></table></figure>

<ol>
<li>运⾏起来后，访问 <a href="http://127.0.0.1:9601/metrics" target="_blank" rel="noopener">http://127.0.0.1:9601/metrics</a> 即可验证</li>
</ol>
<p>⾄此 Exporter 开发完成，其中 8，9 两步中的函数是重点，⽬前仅仅写了⼀些数据进⾏示例，其中的监控指标获取数据就是该部分的主要功能，需要编写对应逻辑获取指标的值。</p>
<h2 id="制作⼀键导⼊包"><a href="#制作⼀键导⼊包" class="headerlink" title="制作⼀键导⼊包"></a>制作⼀键导⼊包</h2><h3 id="Exporter-编译"><a href="#Exporter-编译" class="headerlink" title="Exporter 编译"></a>Exporter 编译</h3><p>蓝鲸监控 Exporter 默认只⽀持 64 位机器运⾏ Exporter。</p>
<h4 id="linux-系统"><a href="#linux-系统" class="headerlink" title="linux 系统"></a>linux 系统</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 编译 windows exporter</span></span><br><span class="line">env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./exporterwindows.exe test_exporter</span><br><span class="line"><span class="comment"># test_exporter 为 GOPATH 下我们创建的⽬录名</span></span><br><span class="line"><span class="comment"># 编译 linux exporter</span></span><br><span class="line">env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./exporter-linux</span><br><span class="line">test_exporter</span><br></pre></td></tr></table></figure>

<h4 id="windows-系统"><a href="#windows-系统" class="headerlink" title="windows 系统"></a>windows 系统</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 编译 windows exporter</span></span><br><span class="line">SET CGO_ENABLED=0</span><br><span class="line">SET GOOS=windows</span><br><span class="line">SET GOARCH=amd64</span><br><span class="line">go build -o ./exporter-windows.exe test_exporter</span><br><span class="line"><span class="comment"># 编译 linux exporter</span></span><br><span class="line">SET CGO_ENABLED=0</span><br><span class="line">SET GOOS=linux</span><br><span class="line">SET GOARCH=amd64</span><br><span class="line">go build -o ./exporter-linux test_exporter</span><br></pre></td></tr></table></figure>



<hr>
<p>参考链接：<br><a href="https://bk.tencent.com/docs/document/5.1/19/600" target="_blank" rel="noopener">蓝鲸监控 - Exporter 开发</a></p>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Ryan Shu
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://notspr.com/2020/11/25/go-prometheus-export/" title="GO语言之Prometheus Exporter开发">https://notspr.com/2020/11/25/go-prometheus-export/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/picture/weixin.png">
            <span class="icon">
              <i class="fab fa-weixin"></i>
            </span>

            <span class="label">WeChat</span>
          </a>
        </div>

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Golang/" rel="tag"><i class="fa fa-tag"></i> Golang</a>
              <a href="/tags/Prometheus/" rel="tag"><i class="fa fa-tag"></i> Prometheus</a>
              <a href="/tags/Exporter/" rel="tag"><i class="fa fa-tag"></i> Exporter</a>
              <a href="/tags/%E7%9B%91%E6%8E%A7/" rel="tag"><i class="fa fa-tag"></i> 监控</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/11/17/pyvmomi-sample/" rel="prev" title="Python之使用pyvmomi管理VMware">
      <i class="fa fa-chevron-left"></i> Python之使用pyvmomi管理VMware
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/11/25/es6-async-await/" rel="next" title="ES6之 async 与 await">
      ES6之 async 与 await <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#自定义组件采集导入流程"><span class="nav-number">1.1.</span> <span class="nav-text">自定义组件采集导入流程</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Exporter-开发"><span class="nav-number">2.</span> <span class="nav-text">Exporter 开发</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Exporter-简介"><span class="nav-number">2.1.</span> <span class="nav-text">Exporter 简介</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Exporter-基础"><span class="nav-number">2.2.</span> <span class="nav-text">Exporter 基础</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Exporter-开发-1"><span class="nav-number">2.3.</span> <span class="nav-text">Exporter 开发</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#制作⼀键导⼊包"><span class="nav-number">3.</span> <span class="nav-text">制作⼀键导⼊包</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Exporter-编译"><span class="nav-number">3.1.</span> <span class="nav-text">Exporter 编译</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#linux-系统"><span class="nav-number">3.1.1.</span> <span class="nav-text">linux 系统</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#windows-系统"><span class="nav-number">3.1.2.</span> <span class="nav-text">windows 系统</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Ryan Shu"
      src="/picture/avatar.jpg">
  <p class="site-author-name" itemprop="name">Ryan Shu</p>
  <div class="site-description" itemprop="description">全栈 | 硬件 | 篮球 | 游戏</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">40</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">34</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">82</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/sususama5555" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sususama5555" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:876324872@qq.com" title="E-Mail → mailto:876324872@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/5330189327" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;5330189327" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://steamcommunity.com/profiles/76561198294148424/" title="steam → https:&#x2F;&#x2F;steamcommunity.com&#x2F;profiles&#x2F;76561198294148424&#x2F;" rel="noopener" target="_blank"><i class="fab fa-steam fa-fw"></i>steam</a>
      </span>
      <span class="links-of-author-item">
        <a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-rss fa-fw"></i>RSS</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://ddoudou.xyz/" title="http:&#x2F;&#x2F;ddoudou.xyz" rel="noopener" target="_blank">豆豆的博客</a>
        </li>
    </ul>
  </div>

      </div>

      <!-- 音乐播放器 -->
      
           <div>
              <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="210" height="110" src="//music.163.com/outchain/player?type=2&id=4226232&auto=1&height=66"></iframe>
           </div>
      

      <!-- 滚动条 -->
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">粤ICP备20063016号-2 </a>
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Ryan Shu</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">180k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">2:44</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/pjax/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>

<script src="/js/utils.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  
  <script data-pjax>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  

    </div>
</body>
</html>
